﻿////using System;
////using System.IO;
////using System.Runtime.Serialization;
////using System.Runtime.Serialization.Formatters.Binary;

////[Serializable]
////class Person
////{
////    public string Name { get; set; }
////    public int Age { get; set; }
////}

////class Program
////{
////    static void Main()
////    {
////        // 创建一个Person对象
////        Person person = new Person { Name = "John", Age = 30 };

////        // 将Person对象序列化为字节数组
////        byte[] bytes = Serialize(person);

////        // 将字节数组反序列化为Person对象
////        Person deserializedPerson = Deserialize<Person>(bytes);

////        Console.WriteLine("反序列化后的Person对象：");
////        Console.WriteLine("Name: " + deserializedPerson.Name);
////        Console.WriteLine("Age: " + deserializedPerson.Age);
////    }

////    // 将对象序列化为字节数组
////    static byte[] Serialize<T>(T obj)
////    {
////        using (MemoryStream memoryStream = new MemoryStream())
////        {
////            BinaryFormatter formatter = new BinaryFormatter();
////            formatter.Serialize(memoryStream, obj);
////            return memoryStream.ToArray();
////        }
////    }

////    // 将字节数组反序列化为对象
////    static T Deserialize<T>(byte[] bytes)
////    {
////        using (MemoryStream memoryStream = new MemoryStream(bytes))
////        {
////            BinaryFormatter formatter = new BinaryFormatter();
////            return (T)formatter.Deserialize(memoryStream);
////        }
////    }
////}


//// C#中Newtonsoft.Json(Json.NET)的使用
//// https://blog.csdn.net/pan_junbiao/article/details/71840964?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170194030116800215091343%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=170194030116800215091343&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-71840964-null-null.142^v96^pc_search_result_base2&utm_term=.NET%20Newtonsoft.Json&spm=1018.2226.3001.4187

//using System;
//using Newtonsoft.Json;

//public class Person
//{
//    public string Name { get; set; }
//    public int Age { get; set; }

//    [Newtonsoft.Json.JsonIgnore]
//    public string Sex { get; set; }
//}

//public class Program
//{
//    public static void Main()
//    {
//        Console.OutputEncoding = System.Text.Encoding.Unicode;
//        // 创建一个 Person 对象
//        Person person = new Person { Name = "John", Age = 30, Sex = "女" };

//        // 将 Person 对象序列化为 JSON 字符串
//        string json = JsonConvert.SerializeObject(person);

//        // 输出 JSON 字符串
//        Console.WriteLine("序列化后的Person对象：" + json);


//        // 将 JSON 字符串反序列化为 Person 对象
//        Person deserializedPerson = JsonConvert.DeserializeObject<Person>(json);

//        // 输出反序列化后的 Person 对象
//        Console.WriteLine("反序列化后的Person对象：");
//        Console.WriteLine(deserializedPerson.Name);
//        Console.WriteLine(deserializedPerson.Age);

//        Console.ReadKey();
//    }
//}
